package 剑指offer;

import java.util.Deque;
import java.util.LinkedList;

public class 剑指offer09用两个栈实现队列 {
    private Deque<Integer> stack1 = null;
    private Deque<Integer> stack2 = null;//辅助栈

    public 剑指offer09用两个栈实现队列() {
        stack1 = new LinkedList<>();
        stack2 = new LinkedList<>();
    }

    public void appendTail(int value) {
        stack1.push(value);
    }

    public int deleteHead() {
        if (stack2.size() != 0){
            return stack2.pop();
        }else {
            if (stack1.size() == 0){
                return -1;
            }else {
                while (stack1.size() != 1){
                    stack2.push(stack1.pop());
                }
                return stack1.pop();
            }
        }
    }
}
